
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  smsBean;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.Hashtable;
import java.util.Vector;

import logger.PoolLogger;

import property.Sequence;
import utility.CharAt;
import utility.ConvertToLower;
import utility.Index;
import utility.MessageGenerator;

import control.Command;
import database.RecordSearch;
import dbmanager.DBManager;
import dbmanager.GetIdName;



public class SmsProperty_details extends SubSmsBean
{
	
	private String mid;
	private String tableName = "property_details";	
	
	private Vector<Object> PropertyVector = new Vector<Object>();
	
	private Vector<Object> NewPropertyVector = new Vector<Object>();/** stores new hashtables for Update.*/
	private Vector<Object> OldPropertyVector = new Vector<Object>();/** stores old hashtables for Update.*/
	
	private Hashtable<Object,Object> ViewHashtable = new Hashtable<Object, Object>();
	
	//private Vector<Object> DeletePropertyVector = new Vector<Object>();
	PoolLogger pl;
	
	public SmsProperty_details() {
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
	}	
	
	
	/**
	 * SmsProperty_details() constructor takes the following parameters,
	 * @param request which is table name for which the request is coming, either master_table or property_details.
	 * @param tableName which stores property_details as a table name.
	 * @param sqlDB stores the DBManager object.
	 * @param process which stores the type of process whether Add, Mod, etc.   
	 * */
	public SmsProperty_details(String request,String msg,String process,String username)
	{
		message = msg;
		 
		gid =new GetIdName();
		this.request = request;
		this.process = process;
		this.userid = username;
	//gid = new GetIdName(sqlDB);
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
		
		System.out.println("SMS::PropertyDetails::Message in property : "+msg);
		pl.info("SMS::PropertyDetails::Message in property : "+msg);
		pl.debug("SMS::PropertyDetails::Message in property : "+msg);
		pl.warn("SMS::PropertyDetails::Message in property : "+msg);
		pl.fatal("SMS::PropertyDetails::Message in property : "+msg);
		pl.error("SMS::PropertyDetails::Message in property : "+msg);
		pl.trace("SMS::PropertyDetails::Message in property : "+msg);
	}	
	
	
	/**
	 * getMessageValidations() method initialises the basic properties of Property_details class.
	 *  like PropertyMap, which stores the Property_details PropertyMap. 
	 *  MasterMap, which stores the reference of master_table entry. 
	 *  @return PropertyMap.  
	 * */
	public Hashtable<Object, Object> initializeToAdd()
	{
		String spChar = null;
		String spPChar = null;	
	
		Hashtable<Object,Object> MasterMap = new Hashtable<Object, Object>();

		Hashtable<Object,Object> PropertyMap = new Hashtable<Object, Object>();
		Hashtable<Object, Object> ErrorMap = new Hashtable<Object, Object>(); 
		
		try
		{
			ResultSet rs = null;
			rs = DBManager.getSelect("select fieldname,spchar from command where msgtype = '" + tableName + "' and process ='" + process + "' order by order1");
			rs.next();
			spChar = rs.getString("spchar");
			rs.next();
			spPChar = rs.getString("spchar");
			rs.close();
			
			Command cp = new Command(tableName);
						
			int index = Index.indexOf(message, spChar);
			int end = Index.indexOf(message, spPChar);
			
			String str= message.substring(0, end);
				
			MasterMap = ConvertToLower.convertHashKey(cp.getHashCommand(tableName,str,process));
		
			if(MasterMap.containsKey("errorinput"))
			{
				return MasterMap;
			}
			mid = MasterMap.get("mid").toString(); 
			
			System.out.println(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
			pl.info(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
			pl.debug(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
			pl.warn(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
			pl.fatal(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
			pl.error(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
			pl.trace(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
		}
		catch(Exception e )
		{
			System.out.println("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			pl.info("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			pl.debug("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			pl.warn("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			pl.fatal("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			pl.error("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			pl.trace("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			PropertyMap.put("ErrorInput", "Enter valid condition ");
			ConvertToLower.convertHashKey(PropertyMap);
			return PropertyMap;		
		}
		
		ErrorMap.putAll(initPropertyDetails());
		ErrorMap.putAll(ConvertToLower.convertHashKey(ErrorMap));
		if(ErrorMap.containsKey("errorinput"))
		{
			return ErrorMap;
		}
		
		insertMid(mid);
		
		return PropertyMap;	
	}
	
	public Hashtable<Object, Object> initializeToDel()
	{
		 
		String spChar = null;
		String spPChar = null;	
	
		Hashtable<Object,Object> MasterMap = new Hashtable<Object, Object>();

		Hashtable<Object,Object> PropertyMap = new Hashtable<Object, Object>();
		Hashtable<Object, Object> ErrorMap = new Hashtable<Object, Object>(); 
		
		try
		{
			ResultSet rs = null;
			rs = DBManager.getSelect("select fieldname,spchar from command where msgtype = '" + tableName + "' and process ='" + process + "' order by order1");
			rs.next();
			spChar = rs.getString("spchar");
			rs.next();
			spPChar = rs.getString("spchar");
			rs.close();
			
			Command cp = new Command(tableName);
						
			int index = Index.indexOf(message, spChar);
			int end = Index.indexOf(message, spPChar);
			
			String str= message.substring(0, end);
				
			MasterMap = ConvertToLower.convertHashKey(cp.getHashCommand(tableName,str,process));
		
			if(MasterMap.containsKey("errorinput"))
			{
				return MasterMap;
			}
			mid = MasterMap.get("mid").toString(); 
			
			System.out.println(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
			pl.info(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
			pl.debug(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
			pl.warn(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
			pl.fatal(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
			pl.error(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
			pl.trace(" Master Name " + message.substring(index+1, end) + " & MID = " + mid);
		}
		catch(Exception e )
		{
			System.out.println("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			pl.info("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			pl.debug("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			pl.warn("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			pl.fatal("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			pl.error("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			pl.trace("SMS::PropertyDetails :: property() :: Exception while creating MasterMap  \n");
			PropertyMap.put("ErrorInput", "Enter valid condition ");
			ConvertToLower.convertHashKey(PropertyMap);
			return PropertyMap;		
		}
		
		ErrorMap.putAll(initPropertyDetails());
		ErrorMap.putAll(ConvertToLower.convertHashKey(ErrorMap));
		if(ErrorMap.containsKey("errorinput"))
		{
			return ErrorMap;
		}
		
		insertMid(mid);
		
		return PropertyMap;	
	}
	/**
	 * this function inserts mid in each hashtable given in PropertyVector
	 *  @param mid - stores mid as a string value
	 */
	@SuppressWarnings("unchecked")
	private void insertMid(String mid)
	{
		for(Object object : PropertyVector)
		{
			Hashtable<Object,Object> tempHash = (Hashtable<Object, Object>)object;
			tempHash.put("mid",mid);		
		}
	}
	
	
	/**
	 * SMS::PropertyDetails::initPropertyDetails() method will initialise the each and every 
	 * properties of the request message in the property_details object.
	 *  @return Hashtable.    
	 * */	
	public Hashtable<Object,Object> initPropertyDetails()
	{
		/*--------------------------------------------------------*/
		/* code for Sequence */
		//Order order = new Order(sqlDB);
		//message = order.getMasterMessage(tableName, message,process);
		/*--------------------------------------------------------*/
		
		//SmsProperty_details spd; // Creating reference for the same class SmsProperty_details.
		int i = 0;	
		String msg = message;
		String PropertySPchar=null;		
		int count=0; /** Stores the total number of special characters in Command message given by User.*/
		ResultSet rs = null;  		
		Hashtable<Object,Object> PropertyMap;
		Hashtable<Object,Object> ErrorMap = new Hashtable<Object, Object>(); 
		
		//GET THE SPECIAL CHARECTOR FOR THE PROPERTY DETAILS
		try
		{
			rs = DBManager.getSelect("select fieldname,spchar from command where msgtype = '" + tableName + "' and process = '"+process+"' and spchar is not null");	//Add Process
			rs.next();
			PropertySPchar = rs.getString("spchar");
			rs.close();	
			
			while(i<msg.length())
			{				
				char ch = CharAt.CharAT(msg,i);
				if(ch == PropertySPchar.toCharArray()[0])
					count ++;
				i++;
			}
			System.out.println("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			pl.info("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			pl.debug("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			pl.warn("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			pl.fatal("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			pl.error("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			pl.trace("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			System.out.println("SMS::MasterClass::initPropertyDetails():: Count : "+count);	
			pl.info("SMS::MasterClass::initPropertyDetails():: Count : "+count);
			pl.debug("SMS::MasterClass::initPropertyDetails():: Count : "+count);
			pl.warn("SMS::MasterClass::initPropertyDetails():: Count : "+count);
			pl.fatal("SMS::MasterClass::initPropertyDetails():: Count : "+count);
			pl.error("SMS::MasterClass::initPropertyDetails():: Count : "+count);
			pl.trace("SMS::MasterClass::initPropertyDetails():: Count : "+count);
		}
		catch (Exception e) 
		{
			System.out.println("SMS::MasterClass::initPropertyDetails():: Exception::");
			pl.info("SMS::MasterClass::initPropertyDetails():: Exception::");
			pl.debug("SMS::MasterClass::initPropertyDetails():: Exception::");
			pl.warn("SMS::MasterClass::initPropertyDetails():: Exception::");
			pl.fatal("SMS::MasterClass::initPropertyDetails():: Exception::");
			pl.error("SMS::MasterClass::initPropertyDetails():: Exception::");
			pl.trace("SMS::MasterClass::initPropertyDetails():: Exception::");
			e.printStackTrace();
			pl.info(e.getMessage());
			pl.debug(e.getMessage());
			pl.warn(e.getMessage());
			pl.fatal(e.getMessage());
			pl.error(e.getMessage());
			pl.trace(e.getMessage());
		}
		
		try
		{
			int cnt = 0;
			
			while(cnt != count)
			{				
				PropertyMap = new Hashtable<Object, Object>();
				//ErrorMap = new Hashtable<Object, Object>(); 
				
				PropertyMap.putAll(property(message, cnt+1));	
				if(PropertyMap.containsKey("errorinput"))
				{
					return PropertyMap;
				}
				else if(!PropertyMap.isEmpty())
				{
					Hashtable<Object,Object> hasht = new Hashtable<Object, Object>();
					hasht.putAll(PropertyMap);
					PropertyVector.add(hasht); // It will stores the PropertyMap of individual property odject.							
				}
				/*try
				{
					if(!PropertyMap.isEmpty())
					{
						String pid = gid.getId(PropertyMap.get("pid").toString());
						if(pid.equals("0"))
						{
							ErrorMap.put("ErrorInput", PropertyMap.get("pid")+" property is not present in master");
						}
												
						if(!PropertyMap.get("pid").equals("0"))
						{
							System.out.println(" PV " + PropertyMap.get("pv"));
							System.out.println(" VT " + PropertyMap.get("vt"));
							String pv =PropertyMap.get("pv").toString(); 	
							if(pv.equals("0") && PropertyMap.containsKey("vt"))
							{	
								if(PropertyMap.get("vt").equals("no$")==true)
									{
									PropertyMap.put("ErrorInput", "Please insert valid property with propertyname and values");							
									ErrorMap.put("ErrorInput", "Please insert valid property with propertyname and values");
									System.out.println("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
									pl.info("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
									pl.debug("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
									pl.warn("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
									pl.fatal("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
									pl.error("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
									pl.trace("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
									}
							}	
							else
							{
								Hashtable<Object,Object> hasht = new Hashtable<Object, Object>();
								hasht.putAll(PropertyMap);
								PropertyVector.add(hasht); // It will stores the PropertyMap of individual property odject.							
							}
						}
						else
						{
							System.out.println("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							pl.info("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							pl.debug("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							pl.warn("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							pl.fatal("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							pl.error("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							pl.trace("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							ErrorMap.put("ErrorInput", "Please insert valid property with propertyname and values");
							PropertyMap.put("ErrorInput", "Please insert valid property with propertyname and values");						
						}
					}	
				}
				catch (Exception e) 
				{
					System.out.println("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue");
					pl.info("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue");
					pl.debug("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue");
					pl.warn("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue");
					pl.fatal("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue");
					pl.error("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue");
					pl.trace("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue");
					ErrorMap.put("ErrorInput", "Please insert valid property with propertyname and values");
					PropertyMap.put("ErrorInput", "Please insert valid property with propertyname and values");
				}
				
				if(ErrorMap.containsKey("ErrorInput"))
				{
					return ErrorMap;
				}*/
				
				cnt++;				
			}
		}
		catch(Exception e)
		{
			System.out.println("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			pl.info("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			pl.debug("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			pl.warn("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			pl.fatal("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			pl.error("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			pl.trace("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			e.printStackTrace();
			pl.info(e.getMessage());
			pl.debug(e.getMessage());
			pl.warn(e.getMessage());
			pl.fatal(e.getMessage());
			pl.error(e.getMessage());
			pl.trace(e.getMessage());
		}
		return ErrorMap;		
	}
	
	public Hashtable<Object,Object> initPropertyDetailsforview()
	{
		/*--------------------------------------------------------*/
		/* code for Sequence */
		//Order order = new Order(sqlDB);
		//message = order.getMasterMessage(tableName, message,process);
		/*--------------------------------------------------------*/
		
		//SmsProperty_details spd; // Creating reference for the same class SmsProperty_details.
		int i = 0;	
		String msg = message;
		String PropertySPchar=null;		
		int count=0; /** Stores the total number of special characters in Command message given by User.*/
		ResultSet rs = null;  		
		Hashtable<Object,Object> PropertyMap;
		Hashtable<Object,Object> ErrorMap = new Hashtable<Object, Object>(); 
		
		//GET THE SPECIAL CHARECTOR FOR THE PROPERTY DETAILS
		try
		{
			rs = DBManager.getSelect("select fieldname,spchar from command where msgtype = '" + tableName + "' and process = '"+process+"' and spchar is not null");	//Add Process
			rs.next();
			PropertySPchar = rs.getString("spchar");
			rs.close();	
			
			while(i<msg.length())
			{				
				char ch = CharAt.CharAT(msg,i);
				if(ch == PropertySPchar.toCharArray()[0])
					count ++;
				i++;
			}
			System.out.println("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			pl.info("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			pl.debug("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			pl.warn("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			pl.fatal("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			pl.error("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			pl.trace("SMS::MasterClass::initPropertyDetails():: Special Char : "+PropertySPchar);
			System.out.println("SMS::MasterClass::initPropertyDetails():: Count : "+count);
			pl.info("SMS::MasterClass::initPropertyDetails():: Count : "+count);
			pl.debug("SMS::MasterClass::initPropertyDetails():: Count : "+count);
			pl.warn("SMS::MasterClass::initPropertyDetails():: Count : "+count);
			pl.fatal("SMS::MasterClass::initPropertyDetails():: Count : "+count);
			pl.error("SMS::MasterClass::initPropertyDetails():: Count : "+count);
			pl.trace("SMS::MasterClass::initPropertyDetails():: Count : "+count);
		}
		catch (Exception e) 
		{
			System.out.println("SMS::MasterClass::initPropertyDetails():: Exception::");
			pl.info("SMS::MasterClass::initPropertyDetails():: Exception::");
			pl.debug("SMS::MasterClass::initPropertyDetails():: Exception::");
			pl.warn("SMS::MasterClass::initPropertyDetails():: Exception::");
			pl.fatal("SMS::MasterClass::initPropertyDetails():: Exception::");
			pl.error("SMS::MasterClass::initPropertyDetails():: Exception::");
			pl.trace("SMS::MasterClass::initPropertyDetails():: Exception::");
			e.printStackTrace();
			pl.info(e.getMessage());
			pl.debug(e.getMessage());
			pl.warn(e.getMessage());
			pl.fatal(e.getMessage());
			pl.error(e.getMessage());
			pl.trace(e.getMessage());
		}
		
		try
		{
			int cnt = 0;
			
			while(cnt != count)
			{				
				PropertyMap = new Hashtable<Object, Object>();
				ErrorMap = new Hashtable<Object, Object>(); 
				
				PropertyMap.putAll(propertyview(message, cnt+1));	
				if(PropertyMap.containsKey("errorinput"))
				{
					return PropertyMap;
				}
				try
				{
					if(!PropertyMap.get("pid").equals("0"))
					{
						System.out.println(" PV " + PropertyMap.get("pv"));
						System.out.println(" VT " + PropertyMap.get("vt"));
							
						if(PropertyMap.get("pv").equals("0")==true && PropertyMap.get("vt").equals("no$")==true)
						{
							//PropertyMap.put("ErrorInput", "Please insert valid property with propertyname and values");							
						//	ErrorMap.put("ErrorInput", "Please insert valid property with propertyname and values");
							System.out.println("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							pl.info("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							pl.debug("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							pl.warn("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							pl.fatal("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							pl.error("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
							pl.trace("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
						}	
						else
						{
							Hashtable<Object,Object> hasht = new Hashtable<Object, Object>();
							hasht.putAll(PropertyMap);
							PropertyVector.add(hasht); // It will stores the PropertyMap of individual property odject.							
						}
					}
					else
					{
						System.out.println("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
						pl.info("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
						pl.debug("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
						pl.warn("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
						pl.fatal("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
						pl.error("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
						pl.trace("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
						//ErrorMap.put("ErrorInput", "Please insert valid property with propertyname and values");
						//PropertyMap.put("ErrorInput", "Please insert valid property with propertyname and values");						
					}
				}
				catch (Exception e) 
				{
					e.printStackTrace();
					PropertyVector.add(PropertyMap);
					System.out.println("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue");
					pl.info("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
					pl.debug("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
					pl.warn("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
					pl.fatal("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
					pl.error("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
					pl.trace("SMS::PropertyDetails ::initPropertyDetails():: Please insert valid property with propertyname and oldvalue \n\n");
					//ErrorMap.put("ErrorInput", "Please insert valid property with propertyname and values");
					//PropertyMap.put("ErrorInput", "Please insert valid property with propertyname and values");
				}
				
				if(ErrorMap.containsKey("ErrorInput"))
				{
					return ErrorMap;
				}
				
				cnt++;				
			}
		}
		catch(Exception e)
		{
			System.out.println("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			pl.info("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			pl.debug("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			pl.warn("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			pl.fatal("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			pl.error("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			pl.trace("SMS::PropertyDetails :: initPropertyDetails() :: Exception while creating a property_details object ----");
			e.printStackTrace();
			pl.info(e.getMessage());
			pl.debug(e.getMessage());
			pl.warn(e.getMessage());
			pl.fatal(e.getMessage());
			pl.error(e.getMessage());
			pl.trace(e.getMessage());
		}	
		return ErrorMap;		
	}
	/** Method for geting individual property from the list of properties.
	 *  @param str which is message string.
	 *  @param cnt which is counter of which property from the property list you want.
	 *  @return Hashtable of the specific property.
	 * */ 
	public Hashtable<Object,Object> property(String str, int cnt)
	{		
	
		Hashtable<Object,Object> tempProperty = new Hashtable<Object, Object>();
		Command cd = new Command(tableName);
		ResultSet rs = null;
		String tempStr = str;
		String retStr;
		String spChar = null;
		int count = 0;
		int start=0, end=0;
		int i=0;
		
		try
		{
			rs = DBManager.getSelect("select fieldname,spchar from command where msgtype = '"+tableName+"' and process = '"+process+"'");
			rs.next();
			spChar = rs.getString("spchar");
			rs.close();
		}
		catch(Exception e )
		{
			System.out.println("SMS::PropertyDetails :: property() :: Exception  \n");
			pl.info("SMS::PropertyDetails :: property() :: Exception  \n");
			pl.debug("SMS::PropertyDetails :: property() :: Exception  \n");
			pl.warn("SMS::PropertyDetails :: property() :: Exception  \n");
			pl.fatal("SMS::PropertyDetails :: property() :: Exception  \n");
			pl.error("SMS::PropertyDetails :: property() :: Exception  \n");
			pl.trace("SMS::PropertyDetails :: property() :: Exception  \n");
			e.printStackTrace();
			pl.info(e.getMessage());
			pl.debug(e.getMessage());
			pl.warn(e.getMessage());
			pl.fatal(e.getMessage());
			pl.error(e.getMessage());
			pl.trace(e.getMessage());
		}
	
		while(i<tempStr.length())
		{
			char ch = CharAt.CharAT(tempStr,i);			
			if(ch == spChar.toCharArray()[0])
			{
				count ++;
				
				if (count == cnt)
				{		
					start = Index.indexOf(str, spChar,i);
					end = Index.indexOf(str, spChar,start+1);
					
					if (end == -1)
					{	
						 retStr = str.substring(start);
						
					}
					else
						retStr = str.substring(start,end);
					
					System.out.println("String needed -->> " + retStr);
					pl.info("String needed -->> " + retStr);
					pl.debug("String needed -->> " + retStr);
					pl.warn("String needed -->> " + retStr);
					pl.fatal("String needed -->> " + retStr);
					pl.error("String needed -->> " + retStr);
					pl.trace("String needed -->> " + retStr);
					tempProperty = ConvertToLower.convertHashKey(cd.getHashCommand(tableName, retStr,process ));
					if(tempProperty.containsKey("errorinput"))
					{
						return tempProperty;
					}
					tempProperty.putAll(ConvertToLower.convertHashKey(tempProperty));
					
				return tempProperty;
				}
			}
			i++;
		}
		return tempProperty;		
	
	}
	
	/** Method for geting individual property from the list of properties.
	 *  @param str which is message string.
	 *  @param cnt which is counter of which property from the property list you want.
	 *  @return Hashtable of the specific property.
	 * */ 
	public Hashtable<Object,Object> propertyview(String str, int cnt)
	{	 
		Hashtable<Object,Object> tempProperty = new Hashtable<Object, Object>();
		Command cd = new Command(tableName);
		ResultSet rs = null;
		String tempStr = str;
		String retStr;
		String spChar = null;
		int count = 0;
		int start=0, end=0;
		int i=0;
		
		try
		{
			rs = DBManager.getSelect("select fieldname,spchar from command where msgtype = '"+tableName+"' and process = '"+process+"'");
			rs.next();
			spChar = rs.getString("spchar");
			rs.close();
		}
		catch(Exception e )
		{
			System.out.println("SMS::PropertyDetails :: property() :: Exception  \n");
			pl.info("SMS::PropertyDetails :: property() :: Exception  \n");
			pl.debug("SMS::PropertyDetails :: property() :: Exception  \n");
			pl.warn("SMS::PropertyDetails :: property() :: Exception  \n");
			pl.fatal("SMS::PropertyDetails :: property() :: Exception  \n");
			pl.error("SMS::PropertyDetails :: property() :: Exception  \n");
			pl.trace("SMS::PropertyDetails :: property() :: Exception  \n");
			e.printStackTrace();
			pl.info(e.getMessage());
			pl.debug(e.getMessage());
			pl.warn(e.getMessage());
			pl.fatal(e.getMessage());
			pl.error(e.getMessage());
			pl.trace(e.getMessage());
		}
	
		while(i<tempStr.length())
		{
			char ch = CharAt.CharAT(tempStr,i);			
			if(ch == spChar.toCharArray()[0])
			{
				count ++;
				
				if (count == cnt)
				{		
					start = Index.indexOf(str, spChar,i);
					end = Index.indexOf(str, spChar,start+1);
					
					if (end == -1)
					{	
						 retStr = str.substring(start);
						
					}
					else
						retStr = str.substring(start,end);
					
					System.out.println("String needed -->> " + retStr);
					pl.info("String needed -->> " + retStr);
					pl.debug("String needed -->> " + retStr);
					pl.warn("String needed -->> " + retStr);
					pl.fatal("String needed -->> " + retStr);
					pl.error("String needed -->> " + retStr);
					pl.trace("String needed -->> " + retStr);
					tempProperty = ConvertToLower.convertHashKey(cd.getHashCommand(tableName, retStr,process ));
					if(tempProperty.containsKey("errorinput"))
					{
						return tempProperty;
					}
					tempProperty.putAll(ConvertToLower.convertHashKey(tempProperty));
					
				return tempProperty;
				}
			}
			i++;
		}
		return tempProperty;		
	
	}
	
	/**
	 * initializeToUpdate() creates two vectors(old & new) of hashtables of different properties to be updated
	 */
	public StringBuffer initializeToUpdate()
	{
		 
			ResultSet rs = null;
			String spcharMod = null, spcharAdd = null, pipeChar = null;
			//gin = new GetIdName(sqlDB);
			int start=0, index=0,end=0;
			Command cp = new Command(request);
			 StringBuffer sbrDTB = new StringBuffer();
			try
			{
				rs = DBManager.getSelect("select spchar from command where msgtype = '" + request + "' and process ='" + process + "'");
				rs.next();
				spcharMod = rs.getString("spchar");
				rs.close();
				
				rs = DBManager.getSelect("select spchar from command where msgtype = '" + request +"' and process = 'add' order by order1");
				rs.next();
				spcharAdd = rs.getString("spchar");
				rs.close();
			}
			catch(Exception e)
			{
				System.out.println("SMS::MasterClass::initializeToUpdate():: Exception while fatching special characters ");
				pl.info("SMS::MasterClass::initializeToUpdate():: Exception while fatching special characters ");
				pl.debug("SMS::MasterClass::initializeToUpdate():: Exception while fatching special characters ");
				pl.warn("SMS::MasterClass::initializeToUpdate():: Exception while fatching special characters ");
				pl.fatal("SMS::MasterClass::initializeToUpdate():: Exception while fatching special characters ");
				pl.error("SMS::MasterClass::initializeToUpdate():: Exception while fatching special characters ");
				pl.trace("SMS::MasterClass::initializeToUpdate():: Exception while fatching special characters ");
				e.printStackTrace();
				pl.info(e.getMessage());
				pl.debug(e.getMessage());
				pl.warn(e.getMessage());
				pl.fatal(e.getMessage());
				pl.error(e.getMessage());
				pl.trace(e.getMessage());
			}
			
			/** This try/catch block will fetch the pipe character from the database.*/
			try
			{	
				rs = DBManager.getSelect("select fieldname,spchar,order1 from command where msgtype='" + tableName + "' and from_master='yes' and process='add' order by order1");					
				rs.absolute(2);
				pipeChar = rs.getString("spchar");
				rs.close();
			}
			catch(Exception e)
			{
				System.out.println("Pipe Char is not Found in Database");
				pl.info("Pipe Char is not Found in Database");
				pl.debug("Pipe Char is not Found in Database");
				pl.warn("Pipe Char is not Found in Database");
				pl.fatal("Pipe Char is not Found in Database");
				pl.error("Pipe Char is not Found in Database");
				pl.trace("Pipe Char is not Found in Database");
			}
			
			int i=0, count=0, cnt=0;
			String msg=message;
			while(i<msg.length())
			{				
				char ch = CharAt.CharAT(msg,i);
				if(ch == spcharMod.toCharArray()[0])
					count ++;
				i++;
			}
			
			System.out.println("SMS::MasterClass::initializeToUpdate():: Special Char : "+spcharMod);
			pl.info("SMS::MasterClass::initializeToUpdate():: Special Char : "+spcharMod);
			pl.debug("SMS::MasterClass::initializeToUpdate():: Special Char : "+spcharMod);
			pl.warn("SMS::MasterClass::initializeToUpdate():: Special Char : "+spcharMod);
			pl.fatal("SMS::MasterClass::initializeToUpdate():: Special Char : "+spcharMod);
			pl.error("SMS::MasterClass::initializeToUpdate():: Special Char : "+spcharMod);
			pl.trace("SMS::MasterClass::initializeToUpdate():: Special Char : "+spcharMod);
			System.out.println("SMS::MasterClass::initializeToUpdate():: Count : "+count);	
			pl.info("SMS::MasterClass::initializeToUpdate():: Count : "+count);
			pl.debug("SMS::MasterClass::initializeToUpdate():: Count : "+count);
			pl.warn("SMS::MasterClass::initializeToUpdate():: Count : "+count);
			pl.fatal("SMS::MasterClass::initializeToUpdate():: Count : "+count);
			pl.error("SMS::MasterClass::initializeToUpdate():: Count : "+count);
			pl.trace("SMS::MasterClass::initializeToUpdate():: Count : "+count);
					
			start = Index.indexOf(message, spcharAdd); // It will stores the index of "*".
			end = Index.indexOf(message, spcharMod);
			
			Hashtable<Object,Object> MasterMap = ConvertToLower.convertHashKey(cp.getHashCommand("master_table", message.substring(0, end),"add"));
			if(MasterMap.containsKey("errorinput"))
			{
				sbrDTB.append(MasterMap.get("errorinput"));
				pl.info(sbrDTB);
				pl.debug(sbrDTB);
				pl.warn(sbrDTB);
				pl.fatal(sbrDTB);
				pl.error(sbrDTB);
				pl.trace(sbrDTB);
				return sbrDTB;
			}
			mid = MasterMap.get("name").toString(); 
			
			try
			{
				rs = DBManager.getSelect("select spchar from command where msgtype = '" + request +"' and process = '"+ process +"' order by order1");
				while(rs.next())
				{
					start = Index.indexOf(message, rs.getString("spchar"), start+1);  // It will stores the index of "$".
					if(start != -1)
						break;					
				}
				rs.close();
			}catch (SQLException e2){}			
		
			index = Index.indexOf(message, pipeChar, start);  // It will stores the index of "|".	
			String dtodStr = null;
			while (cnt != count)
			{
				Hashtable<Object,Object> oldProperty = new Hashtable<Object,Object>();
				Hashtable<Object,Object> newProperty = new Hashtable<Object,Object>();
							
				try
				{			
					end = Index.indexOf(message, spcharMod, start+1);							
									
					if (end == -1)
					{	
						 dtodStr = message.substring(start);
						end =message.length();
					}
					else
						dtodStr = message.substring(start,end);				
			
					System.out.println(" Doller to Doller String -- >> " + dtodStr);
					
					if(dtodStr.contains(pipeChar))
					{
						
						index = Index.indexOf(message, pipeChar, start);	
						newProperty = ConvertToLower.convertHashKey(cp.getHashCommand(tableName, message.substring(start, index),process)); //new
						if(newProperty.containsKey("errorinput"))
						{
							sbrDTB.append(newProperty.get("errorinput"));
							pl.info(sbrDTB);
							pl.debug(sbrDTB);
							pl.warn(sbrDTB);
							pl.fatal(sbrDTB);
							pl.error(sbrDTB);
							pl.trace(sbrDTB);
							return sbrDTB;
						}						
						newProperty.put("mid",mid);						
					
						oldProperty = ConvertToLower.convertHashKey(cp.getHashCommand(tableName, message.substring(index, end),"add")); //old
						if(oldProperty.containsKey("errorinput"))
						{
							sbrDTB.append(oldProperty.get("errorinput"));
							pl.info(sbrDTB);
							pl.debug(sbrDTB);
							pl.warn(sbrDTB);
							pl.fatal(sbrDTB);
							pl.error(sbrDTB);
							pl.trace(sbrDTB);
							return sbrDTB;
						}
						oldProperty.put("mid",mid);							
						
						index = Index.indexOf(message, pipeChar, end);
						start = end;
						end = index;	
						
						OldPropertyVector.add(oldProperty);						
					}
					else
					{
						newProperty = ConvertToLower.convertHashKey(cp.getHashCommand(tableName, message.substring(start, end),process));	
						if(newProperty.containsKey("errorinput"))
						{
							sbrDTB.append(newProperty.get("errorinput"));
							pl.info(sbrDTB);
							pl.debug(sbrDTB);
							pl.warn(sbrDTB);
							pl.fatal(sbrDTB);
							pl.error(sbrDTB);
							pl.trace(sbrDTB);
							return sbrDTB;
						}						
						newProperty.put("mid",mid);							
									
						start = end;
						index = start;								
					}					

					NewPropertyVector.add(newProperty);						
				}
				catch (Exception e) {
					// TODO: handle exception
				}					
					cnt++;
			}
			pl.info(sbrDTB);
			pl.debug(sbrDTB);
			pl.warn(sbrDTB);
			pl.fatal(sbrDTB);
			pl.error(sbrDTB);
			pl.trace(sbrDTB);
		return sbrDTB;
	}
	
	
	/**
	 * initializeToView() creates hashtables of property details to be viewed 
	 * @return stringbuffer containing details of property details to be viewed  
	 */
	public StringBuffer initializeToView() 
	{
		StringBuffer sbrProperty=new StringBuffer();
		
		
		String spChar="";
		String spPChar="";
		try {
			ResultSet rs = null;
			rs = DBManager.getSelect("select fieldname,spchar from command where msgtype = '" + tableName + "' and process ='" + process + "' order by order1");
			rs.next();
			spChar = rs.getString("spchar");
			rs.next();
			spPChar = rs.getString("spchar");
			rs.close();
		} catch (SQLException e) 
		{
			e.printStackTrace();
		}
		
		Command cp = new Command(tableName);
					
		int index = Index.indexOf(message, spChar);
		int end = Index.indexOf(message, spPChar);
		
		String str= message.substring(0, end);
			
		ViewHashtable = ConvertToLower.convertHashKey(cp.getHashCommand(tableName,str,process));
	
		if(ViewHashtable.containsKey("errorinput"))
		{
			return new StringBuffer("Error input");
		}
		mid = ViewHashtable.get("mid").toString(); 
		
		
		
		
				
		
		//SmsProperty_details spd = new SmsProperty_details(request,message,sqlDB,process,userid);
		
		initPropertyDetailsforview();
		
		return sbrProperty;
	}
	
	
	public Hashtable<Object,Object> initializeToDelete() 
	{
		 
		Hashtable<Object,Object> tempHash = new Hashtable<Object, Object>();
		
		tempHash.putAll(initializeToAdd());
		
		return tempHash;
	}
	
	
	
	public String getId() {
		return mid;
	}
	
	public Hashtable<Object,Object> getViewHashtable() {
		return ViewHashtable;
	}
	
	public Vector<Object> getPropertyVector() 
	{
		return PropertyVector;
	}
	
	public Vector<Object> getOldPropertyVector() {
		
		return OldPropertyVector;
	}
	
	public Vector<Object> getNewPropertyVector() {
		
		return NewPropertyVector;
	}
	
	/**
	 * is called when process is to insert in database
	 */
	/*public void setProcessToAdd()
	{	
		//add
		Hashtable<Object,Object> PropertyMap = new Hashtable<Object, Object>();		
		
		PropertyMap.putAll(initializeToAdd());
		
		System.out.println(PropertyVector);
		
		if(!PropertyMap.containsKey("ErrorInput"))
		{				
			pdBean = new Property_details_Bean();
			
			pdBean.setDBManager(sqlDB);
			pdBean.setReqParam(reqParam);
			//pdBean.setMid(mid);
			pdBean.setOldPropertyVector(PropertyVector);		
			
			pdBean.insert();
		}			
	}*/
	
	/**
	 * is called when process is to update in database
	 */
	/*public void setProcessToUpdate()
	{						
		//mod	
		sbrDTB = new StringBuffer();
		sbrDTB.append(initializeToUpdate());
		
		System.out.println("old "+OldPropertyVector);
		System.out.println("new "+NewPropertyVector);		

		//if(!sbrDTB.containsKey("ErrorInput"))
		//{				
			pdBean = new Property_details_Bean();
			
			pdBean.setDBManager(sqlDB);
			pdBean.setReqParam(reqParam);
			pdBean.setProcess(process);
			if(!OldPropertyVector.isEmpty())
				pdBean.setOldPropertyVector(OldPropertyVector);	
			if(!NewPropertyVector.isEmpty())
				pdBean.setNewPropertyVector(NewPropertyVector);
			
			pdBean.update();
		//}		
		
	}*/
	
	public StringBuffer generatesms(StringBuffer strbuffer)
	{
		StringBuffer stringbuffer = new StringBuffer();
		if(!reqParam.getKeyword().equals("11"))
		{	
			if(reqParam.getKeyword().length()!=0 )
			{
				Sequence sequence = new Sequence();
				sequence.iniPool();
				String splitheading[] = strbuffer.toString().split("\n")[0].split("\t");
				String splitdata[] = strbuffer.toString().split("\n");
				Hashtable<Object, Object> property =new Hashtable<Object, Object>();
				
				for(int i=0;i<splitdata.length;i++)
				{	
					String split[] = splitdata[i].split("\t");				
					try {
						for(int j=0;j<splitheading.length;j++)
							property.put(splitheading[j], split[j]);
					} catch (Exception e) 
					{
						e.printStackTrace();
					}
					stringbuffer.append(sequence.getReponses(reqParam.getKeyword(), property)+"#");
					
				}
				property.clear();
				String value=gid.getId(reqParam.getKeyword());
				property.put("mid", value);
				property.put("pid", gid.getId("event"));
				RecordSearch recordsearch =new RecordSearch();
				recordsearch.setConditionMap(property);
				String line[]=recordsearch.getArrayFromResultSet();	
				
				Hashtable<Object, Object> event =new Hashtable<Object, Object>();
				event.put("username", reqParam.getUsername());
				event.put("process", reqParam.getProcess());
				event.put("data", stringbuffer);
				event.put("status", "0");
				
				for(int i=0;i<line.length;i++)
				{
					String splitline[] = line[i].split("\t");
					event.put("masterobject", value);
					DBManager.getInsert("eventprocess", event);
				}
			}	
		}	
		else
		{
			String splitheading[] = strbuffer.toString().split("\n")[0].split("\t");
			String splitdata[] = strbuffer.toString().split("\n");
			Hashtable<Object, Object> property =new Hashtable<Object, Object>();
			MessageGenerator mg =new MessageGenerator();
			for(int i=1;i<splitdata.length;i++)
			{	
				String split[] = splitdata[i].split("\t");				
				try {
					for(int j=0;j<splitheading.length;j++)
						property.put(splitheading[j], split[j]);
				} catch (Exception e) 
				{
					e.printStackTrace();
				}
				stringbuffer.append(mg.messagegerat(tableName,property,process)+"#");	
			}
		}	
		return stringbuffer;
	}
	/*@SuppressWarnings("unchecked")
	public void processSms()
	{		
		//add	
		if(process.equalsIgnoreCase("add"))
			processAdd();
		else
			processMod();//mod		
	}
	
	public void setProcessToView()
	{						
		//view	
		sbrDTB = new StringBuffer();
		sbrDTB.append(initializeToView());
	
		System.out.println(ViewHashtable);
	
		pdBean = new Property_details_Bean();
			
		pdBean.setDBManager(sqlDB);
		pdBean.setReqParam(reqParam);
		pdBean.setProcess(process);
		
		pdBean.setViewHashtable(ViewHashtable);
			
		pdBean.view();
			
		
	}
	*/
	
}
